12. Writing Good Unit Tests
Writing Good Unit Tests
ND079 JPND C3 L4 A10 Writing Good Unit Tests V2
Unit Test Tips:
- Short - Simple unit tests that verify a single, concrete requirement.
- Names - Clear names that are communicate the requirement they test.
- Success and Failure - In addition to testing for expected results, test for failures and invalid states.
- Speed - Tests should run quickly, because they should run often. Slow tests often indicate problem code.
- Minimize Pre-conditions - Don't overuse
@BeforeEach
to do things that are not relevant to every test. This makes your tests slower and obscures the requirements. - Thorough - Test all branching conditions.